package com.zhengtoon.mctoon.conv.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zhengtoon.mctoon.conv.bean.CityItem;
import com.zhengtoon.mctoon.conv.bean.ConfigDict;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 审核配置项字典读取类
 *
 * @author liuzhenhua
 * @since 2017-05-09
 */
public class ConfigDictUtils {
    private final static Logger log = LoggerFactory.getLogger(ConfigDictUtils.class);

    private final static String REJECT_REASON_DICT_STRING = SysConfig.getPropertyValue("config.reject_reason_dict");

    private final static String DEAL_TYPE_DICT_STRING = SysConfig.getPropertyValue("config.deal_type_dict");


    public final static Integer REJECT_TYPE = 1;

    public final static Integer DEAL_TYPE = 2;


    /**
     * 获取配置字典项 144637
     *
     * @return List<ConferenceTypeDict>
     */
    // TODO 目前暂时使用配置文件的形式
    public static List<ConfigDict> getConfigDictFromProp(Integer type) {

        List<ConfigDict> entity = new ArrayList<>();
        if (REJECT_TYPE.equals(type)) {
            entity = JSON.parseObject(REJECT_REASON_DICT_STRING, new TypeReference<List<ConfigDict>>() {
            });
        } else if (DEAL_TYPE.equals(type)) {
            entity = JSON.parseObject(DEAL_TYPE_DICT_STRING, new TypeReference<List<ConfigDict>>() {
            });
        }


        return entity;
    }

    /**
     * 根据字典编码获取字典值
     *
     * @param type
     * @param dictCode
     * @return
     */
    public static String getDictValueByCode(Integer type, Integer dictCode) {
        List<ConfigDict> entity = getConfigDictFromProp(type);
        for (ConfigDict item : entity) {
            if (item.getDictCode().equals(dictCode.toString())) {
                return item.getDictValue();
            }
        }

        return null;
    }

    /**
     * 从城市服务查询的字典项
     *
     * @return
     */
    public static List<ConfigDict> queryCityDictFromCityService() {

        List<ConfigDict> configDictList = new ArrayList<>();

        List<CityItem> cityItemList = CityIntegralUtils.getCityIntegralConfig();

        for (CityItem item : cityItemList) {
            ConfigDict config = new ConfigDict();
            config.setDictCode(item.getId() + "");
            config.setDictValue(item.getItem() + ",奖励" + item.getScore() + "分");
            configDictList.add(config);
        }
        return configDictList;
    }

    public static void main(String[] args) {

    }
}
